/**
* Copyright @ 2023 iAuto (Shanghai) Co., Ltd.
* All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are NOT permitted except as agreed by
* iAuto (Shanghai) Co., Ltd.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/



import request from '@/utils/request';
import base from "./base";

// 上传文件 编辑器
export function uploadFile(file: any, params: any) {
  const { fileMd5, storageType } = params;
  return request.post(`/${base.API}/ms-soa-filestorage/${base.VERSION}/files`, {
    requestType: 'form',
    params: {
      fileMd5,
      storageType,
    },
    data: file,
  });
}

// 文件下载
export function downLoadFile(uuid: any) {
  return request.get(`/${base.API}/ms-soa-filestorage/${base.VERSION}/files/_download`, {
    params: {
      uuid
    }
  })
}

// 获取预上传地址和 uuid
export function getUploadSignedUrl(params: {
  // storageType: string;
  // expires: number;
  fileName: string;
  md5: string;
}) {
  return request.get(`/${base.API}/ms-soa-filestorage/${base.VERSION}/upload/getSignedUrl`, {
    params: {
      storageType: 'SCENE',
      expires: 3600,
      ...params
    }
  });
}

// 使用预上传地址上传
export function uploadSignedUrl(url:string, file: any) {
  return request.put(url, {
    data: file
  });
}